package br.unipar.blog.view.action.usuario;

import br.unipar.blog.view.action.AbstractReportAction;
import br.unipar.blog.view.action.JasperJsfUtils;
import java.util.HashMap;
import java.util.Map;

public class CadastroUsuarioReportAction extends AbstractReportAction {

    @Override
    public CadastroUsuarioFactory cadastroUsuarioFactory;
    
    List<CadastroUsuarioVo> voList;
    
    public void imprimir() {
        voList = cadastroUsuarioFactory.buscarTodos();
        JasperJsfUtils.exportToPdf(createReport(), "relatorioDeUsuario");
    }

    @Override
    public JasperPrint createReport() {
        
        
        List<Map<String, ?>> valueList = new ArrayList<Map<String, ?>>();
        
        for (CadastroUsuarioVo vo : voList) {
            Map<String, Object> valueMap = new HashMap<String, ?>();
            valueMap.put("codigo", vo.getId());
            valueMap.put("nome", vo.getNome());
            valueMap.put("senha", vo.getSenha());
            
            valueList.add(valueMap);
        }

        return createReport("/usuarioReport.jasper", valueList);
    }
    
}
